					**This file runs ITS specifications**	

			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

	
use removalcounts, clear

set matsize 2000

**
*Make indicator variables
**


gen centeredmonth = month-policymonth

replace centeredmonth = 0 if policymonth == .

*Indicator variables for each centered month variable (only 5 years before and after)
tab centeredmonth if centeredmonth >= -10 & centeredmonth <= 10, gen(indcentered)

* Rename these 
forv j = 1/10{
	loc k = abs(`j' - 11)
	rename indcentered`j' indcenteredN`k'
}
forv j = 11/21{
	loc k = `j' - 11
	rename indcentered`j' indcentered`k'
}

*Now set first indicator to include all previous obs and last to include all subsequent
replace indcenteredN10 = 1 if centeredmonth <= -10
replace indcentered10 = 1 if centeredmonth >= 10 

* Change order of indcenteredN0 (for which y - y* = 0) so that is omitted category
order indcentered0, last

*Replace missing months with zeros 
foreach var of varlist ind* {
replace `var' = 0 if `var' != 1
}



***
*Run regressions and produce figures
***

**
* All counts
**

glm countymonthlytotal  i.statecounty i.month indcenteredN10-indcentered10 , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("All") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(a, replace)

restore

**
* Threat 1 counts
**

glm threat1count indcenteredN10-indcentered10 i.month i.statecounty  , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)

* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1


twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with Category 1 Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(b, replace)

restore




**
* Threat 0 counts
**


glm threat0count indcenteredN10-indcentered10 i.month i.statecounty  , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)

* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1


twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with No Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(c, replace)
	

restore


**
* Violent counts
**

glm violentcount indcenteredN10-indcentered10 i.month i.statecounty  , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with Violent Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(d, replace)
	
restore

**
*  Figure 2
**

graph combine a b c d, xsize(3) ysize(1.5) ///
l1title("Change in Log Deportations Relative to Date of Policy", size(med)) ///
b1title("Months Since Sanctuary Policy")

graph export "fig2.pdf", replace






			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
	

*-------------------------------------------------------------------------------
* Now same but CAP dependent variables
*-------------------------------------------------------------------------------


**
* All counts
**

glm capcount  i.statecounty i.month indcenteredN10-indcentered10 , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-2(.5)0.5, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("All") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(a, replace)

restore

**
* Threat 1 counts
**

glm capthreat1 indcenteredN10-indcentered10 i.month i.statecounty  , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)

* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1


twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-2(.5)0.5, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with Category 1 Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(b, replace)

restore




**
* Threat 0 counts
**


glm capthreat0 indcenteredN10-indcentered10 i.month i.statecounty  , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)

* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1


twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-2(.5)0.5, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with No Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(c, replace)
	

restore


**
* Violent counts
**

glm capviolent indcenteredN10-indcentered10 i.month i.statecounty  , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-2(.5)0.5, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with Violent Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(d, replace)
	
restore

**
*  Figure S14
**

graph combine a b c d, xsize(3) ysize(2) ///
l1title("Change in Log Deportations Relative to Date of Policy", size(med)) ///
b1title("Months Since Sanctuary Policy") ti("Local-Arrest Deportations")

graph export "s14.pdf", replace



**
* CAP Early Policies
**

glm capcount  i.statecounty i.month indcenteredN10-indcentered10 if policym < m(2014m6) | policym > m(2015m12), family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-2(.5)0.5, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("Local-Arrest Deportations Before June 2014") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(a, replace)

restore

**
* CAP Late Policies
**

glm capcount  i.statecounty i.month indcenteredN10-indcentered10 if policym >= m(2014m6) , family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr  * sqrt(deviance/df)


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-2(.5)0.5, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("Local-Arrest Deportations After June 2014") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(b, replace)


restore

***
*Figure S15
***



graph combine a b, xsize(6) ysize(2) ///
l1title("Change in Log Deportations" "Relative to Date of Policy", size(med)) ///
b1title("Months Since Sanctuary Policy") ti("")

graph export "s15.pdf", replace


*-------------------------------------------------------------------------------
* Now event study for appendix with linear regression and logged dependent variable
*-------------------------------------------------------------------------------


**
* All counts
**

areg logcountymonthlytotal i.month indcenteredN10-indcentered10 , absorb(statecounty) ///
cluster(state) 

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  
gen lb = coef - 1.96 * stderr 


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("All") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(a, replace)

restore

**
* Threat 1 counts
**

areg logthreat1count i.month indcenteredN10-indcentered10 , absorb(statecounty) ///
cluster(state) 

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  
gen lb = coef - 1.96 * stderr 

* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1


twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with Category 1 Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(b, replace)

restore




**
* Threat 0 counts
**


areg logthreat0count i.month indcenteredN10-indcentered10 , absorb(statecounty) ///
cluster(state) 

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  
gen lb = coef - 1.96 * stderr 

* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1


twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with No Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(c, replace)
	

restore


**
* Violent counts
**


areg logviolentcount i.month indcenteredN10-indcentered10 , absorb(statecounty) ///
cluster(state) 

preserve

* Get coef
regsave indcenteredN10-indcentered10, detail(all)

* Create variables
gen ub = coef + 1.96   * stderr  
gen lb = coef - 1.96 * stderr 


* Generate time variable and other graphing stuff
gen time = _n-11
replace time = time+1 if time > -1

twoway (rspike ub lb time , lw(0.3) lc(gray)) (scatter coef time , msize(small) msymbol(circle) ), ///
	yli(0, lpattern(dash) lc(black)) ///
	ylab(-1.4(.2)0.6, labsize(small) angle(horizontal)) xlab(-10(2)10, labsize(small)) ///
	title("People with Violent Convictions") ///
	ytitle("") xtitle("") ///
	graphregion( fcolor(white) lcolor(white)) plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none)) ///
	legend(off) xsize(5) ysize(3) name(d, replace)
	
restore

**
* Figure S10
**

graph combine a b c d, xsize(3) ysize(2) ///
l1title("Change in Log Deportations Relative to Date of Policy", size(med)) ///
b1title("Months Since Sanctuary Policy")

graph export "s10.pdf", replace







